package com.klhappy.houyuan.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.klhappy.houyuan.R;
import com.klhappy.houyuan.bean.DingDanBean.OrderDetail;
import com.klhappy.houyuan.bean.DingDanBean.PayBean;
import com.klhappy.houyuan.constant.UrlConstant;
import com.klhappy.houyuan.view.ImageManager;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by MrPu on 15/12/12.
 */
public class PayGoodsAdapter extends BaseAdapter {
    private Context context;
    private List<OrderDetail> orderDetails;

    public PayGoodsAdapter(Context context, List<OrderDetail> orderDetails) {
        this.context = context;
        this.orderDetails = orderDetails;
    }

    @Override
    public int getCount() {
        return orderDetails.size();
    }

    @Override
    public Object getItem(int position) {
        return orderDetails.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_pay_goods, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        ImageManager.loadImage(UrlConstant.BASE_URL + orderDetails.get(position).getG_icon(), holder.ibImage);
        holder.tvDes.setText(orderDetails.get(position).getG_name());
        holder.tvPrice.setText("￥" + orderDetails.get(position).getG_price() + "/" + orderDetails.get(position).getG_unit());
        holder.tvCount.setText("x" + orderDetails.get(position).getNo());

        return convertView;
    }

    static class ViewHolder {
        @InjectView(R.id.iv_image)
        ImageView ibImage;
        @InjectView(R.id.tv_des)
        TextView tvDes;
        @InjectView(R.id.tv_price)
        TextView tvPrice;
        @InjectView(R.id.tv_count)
        TextView tvCount;

        public ViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }

}
